package cn.wj.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.wj.base.BaseAction;
import cn.wj.entity.Department;
import cn.wj.entity.Employee;

@Controller
@Scope("prototype")
@ParentPackage("struts-default")
public class DepartmentAction extends BaseAction<Department>{

	private static final long serialVersionUID = 1L;

	private String sid;
	private String oper;
	private Employee emp;
	private String sn;
	
	@Action(value="adddept",results={@Result(type="chain",name="success",params={"ActionName","addposi","namespace","/jsp/system/user"}),@Result(type="chain",name="input",params={"ActionName","addemp","namespace","/jsp/common"})})
	public String execute(){
		if(oper!=null){
			List<Department> deptAll=this.deptservice.findAll();
		    ActionContext.getContext().put("deptlist",deptAll);
		    ActionContext.getContext().put("sn", sn);
		    ActionContext.getContext().put("oper", oper);
		    return INPUT;
		}
		else{
			List<Department> deptAll=this.deptservice.findAll();
		    ActionContext.getContext().put("deptlist",deptAll);
		    return SUCCESS;
		}
	}
	
	@Action(value="get",results={@Result(type="chain",name="success",params={"ActionName","getPosition","namespace","/jsp/system/user"}),@Result(type="chain",name="input",params={"ActionName","getPosition","namespace","/jsp/system/user"})})
	public String getDept(){
		if(oper==null){
			int sid1=Integer.parseInt(sid);
			Department dept=this.deptservice.get(sid1);
			ActionContext.getContext().put("department", dept);
			ActionContext.getContext().put("employee", emp);
		    return SUCCESS;
		}
		else{
			int sid1=Integer.parseInt(sid);
			Department dept=this.deptservice.get(sid1);
			ActionContext.getContext().put("department", dept);
			ActionContext.getContext().put("mess", oper);
			ActionContext.getContext().put("employee", emp);
		    return INPUT;
		}
	}
	
	
	
/*	@Action(value="deptList",results={@Result(location="/jsp/system/department/list.jsp",name="success")})
	public String deptList(){
		List<Department> deptAll=this.deptservice.findAll();
	    ActionContext.getContext().put("deptlist",deptAll);
	    return SUCCESS;
	}*/

	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	public String getOper() {
		return oper;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public Employee getEmp() {
		return emp;
	}

	public void setEmp(Employee emp) {
		this.emp = emp;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		
		this.sn = sn;
	}
	
	
	
	
}

